package cn.school.demo.ui.setting

import android.graphics.Color
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.navigation.fragment.findNavController
import cn.school.demo.MyApplication
import cn.school.demo.R
import cn.school.demo.databinding.FragmentSettingBinding
import com.mylhyl.circledialog.CircleDialog

class SettingFragment : Fragment() {

    private lateinit var binding: FragmentSettingBinding
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        MyApplication.systemBarSetting(MyApplication.DARK, requireActivity())
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_setting, container, false)
        binding.vw = this
        binding.lifecycleOwner = viewLifecycleOwner
        return binding.root
    }

    fun gotoMy() =
        MyApplication.goto(R.id.action_Setting_to_My, findNavController(), requireFragmentManager())

    fun gotoEdit() {
        MyApplication.apply {
            navigateThing["My"] = "Setting"
            goto(R.id.action_Setting_to_Edit, findNavController(), requireFragmentManager())
        }
    }

    fun loginOut() {
        CircleDialog.Builder()
            .setText("你确定要退出登录吗？")
            .setTextColor(Color.RED)
            .setPositive("确定", View.OnClickListener {
                MyApplication.apply {
                    goto(
                        R.id.action_Setting_to_Login,
                        findNavController(),
                        requireFragmentManager()
                    )
                    user = null
                }
            }).setNegative("取消", null).show(fragmentManager)
    }

    fun aboutMine() {
        CircleDialog.Builder().setText("学弈有道  V1.0").setNegative("确定", null).show(fragmentManager)
    }

    fun gotoModifyPwd() = MyApplication.goto(
        R.id.action_Setting_to_ModifyPwd,
        findNavController(),
        requireFragmentManager()
    )

    fun gotoUpdatePhone() = MyApplication.goto(
        R.id.action_Setting_to_UpdatePhone,
        findNavController(),
        requireFragmentManager()
    )

}